package com.example.flowable.controller;

import com.example.annotations.*;
import com.example.flowable.model.FlowableModel;
import com.example.flowable.service.FlowableModelService;
import com.example.flowable.service.TableModelService;

import java.util.Map;

/**
 * @Classname FLowableTemplaeteController
 * @Description TODO
 * @Date 2022/9/3 14:34
 * @Created by XiongXiong
 * @Author: X.I.O
 *
 * 流程模板处理
 */
@Auth
@Controller(value = "/flowprocess")
public class FLowableTemplaeteController {

    @Autowired
    private FlowableModelService flowableModelService;

    @Autowired
    private TableModelService tableModelService;

    @GetMapping("/index")
    public String getFlowableTemplate(
            Map<String,Object> map,
            @Param(value = "processId",desc = "流程id")Integer processId,
            @Param(value = "id",desc = "数据id",required = false)Integer id){

        FlowableModel flowableModel=flowableModelService.getById(processId);
        if(flowableModel==null){
            map.put("msg","流程模型不存在");
            return "form/error.html";
        }
        if(flowableModel.getFromId()==null){
            map.put("msg","未配置表单");
            return "form/error.html";
        }

        map.put("id",String.valueOf(processId));
        map.put("dataId",id==null? "" : String.valueOf(id));
        return "form/processForm.html";
    }

//    @GetMapping("/getfromdata")
//    public String getFromDataController(Map<String,Object> map,
//                                        @Param(value = "processId",desc = "流程id")Integer processId,
//                                        @Param(value = "id",desc = "数据id")Integer id){
//        FlowableModel flowableModel=flowableModelService.getById(processId);
//        if(flowableModel==null){
//            map.put("msg","流程模型不存在");
//            return "form/error.html";
//        }
//        if(flowableModel.getFromId()==null){
//            map.put("msg","未配置表单");
//            return "form/error.html";
//        }
//        map.put("id",processId);
//        map.put("dataId",id==null? "" : id);
//        return "form/processForm.html";
//    }
}
